﻿
using Dapper;
using HBase;
using HBase.db;
using System;
using System.Collections.Generic;
using System.Linq;
namespace hCommand {
    public abstract class AbsWCSServer :AbsWMSBaseServer, IWCSServer {

        
        
        public BParam getParam(string driveType ,int driveId ,string key) {
            string sql = "select * from b_Param where drive_Type=@driveType and drive_index=@driveId and key_Code=@key";
            BParam mechineStatus = readConn().QueryUnique<BParam>(sql ,new { driveType ,driveId ,key });
            return mechineStatus;
        }
        public List<BParam> getParams(string driveType ,int driveId) {
            string sql = "select * from b_Param  where 1=1 ";
            if( !String.IsNullOrWhiteSpace(driveType) ) {

                sql += " and drive_Type=@driveType";
            }

            if( driveId > 0 ) {

                sql += " and drive_index=@driveId";
            }
            return readConn().Query<BParam>(sql ,new { driveType ,driveId }).ToList();
        }
        public List<BParam> getParams() {
            string sql = "select * from b_Param";
            return readConn().Query<BParam>(sql ,new { }).ToList();
        }
        public bool update(string driveType ,int driveId ,string key ,int value) {
            string sql = "update b_Param set v=@value where  drive_Type=@driveType  and key_Code=@key ";
            if( driveId != 0 ) {
                sql += " and drive_index = @driveId";
            }
            int i = opConn().Execute(sql ,new { value ,driveType ,key ,driveId });

            MyCache.setDirty<BParam>(driveType);
            if( i != 1 ) {
                return false;
            } else {
                return true;
            }
        }
        public bool update( int id,   int value) {
            string sql = "update b_Param set v=@value where  id=@id ";
             
            int i = opConn().Execute(sql, new { value, id });

            MyCache.setDirty<BParam>(id);
            if (i != 1) {
                return false;
            } else {
                return true;
            }
        }
    }
}
